package com.book.utils;

import java.util.ArrayList;
import java.util.List;  
  
public class ListChunker { //list分页
    public static <T> List<List<T>> chunkList(List<T> list, int chunkSize) {  
        List<List<T>> chunks = new ArrayList<>();  
        for (int i = 0; i < list.size(); i += chunkSize) {  
            int end = Math.min(i + chunkSize, list.size());  
            List<T> chunk = list.subList(i, end);  
            chunks.add(new ArrayList<>(chunk));  
        }  
        return chunks;  
    }
}